package com.bidevalution.controller.api;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bidevalution.business.service.BeMethodLayoutService;
import com.bidevalution.controller.dto.BeMethodColumnDTO;
import com.bidevalution.dao.entity.BeLayoutConfig;
import com.bidevalution.dao.entity.BeMethodDefine;
import com.bidevalution.dao.entity.BeMethodLayout;
import com.bidevalution.service.layout.ColumnHeader.ColumnType;
import com.qtp.core.model.Response;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/beMethodLayout")
@Api(tags = "环节配置数据区域布局管理")
public class BeMethodLayoutController {
	@Autowired
	private BeMethodLayoutService beMethodLayoutService;

	@PostMapping("/saveMethodLauout")
	@ApiOperation(value = "保存布局设置的数据", notes = "保存布局设置的数据")
	public Response<String> save(BeMethodColumnDTO beMethodColumnDTO) {
		BeMethodLayout beMethodLayout = new BeMethodLayout();
		beMethodLayout.setLayoutCode(beMethodColumnDTO.getLayoutCode());
		beMethodLayout.setCreateTime(new Date());
		beMethodLayout.setLayoutText(beMethodColumnDTO.getLayoutText());
		beMethodLayout.setMethodStepId(beMethodColumnDTO.getMethodStepId());
		beMethodLayout.setSqlConfig(beMethodColumnDTO.getSqlConfig());
		beMethodLayout.setClickFunction(beMethodColumnDTO.getClickFunction());
		beMethodLayout.setDisplayOrder(beMethodColumnDTO.getDisplayOrder());
		beMethodLayout.setCascadeLayoutCode(beMethodColumnDTO.getCascadeLayoutCode());
		beMethodLayout.setUpdateTime(new Date());
		beMethodLayoutService.save(beMethodLayout, beMethodColumnDTO.getColumns());
		return Response.ok();
	}

	@GetMapping("/getColumnTypeList")
	@ApiOperation(value = "查询字段类型列表", notes = "返回字段类型列表", response = BeLayoutConfig.class)
	public Response<Map<String, String>> getColumnTypeList() {
		Map<String, String> dataMap = new HashMap<String, String>();
		for (ColumnType columnType : ColumnType.values()) {
			dataMap.put(columnType.getCode(), columnType.getText());
		}
		return Response.ok(dataMap);
	}

	@ApiOperation(value = "查询环节布局详细信息", notes = "根据主键查询环节布局详细信息", response = BeMethodLayout.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "methodStepId", value = "主键", required = true, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "layoutCode", value = "主键", required = true, dataType = "String", paramType = "query") })
	@GetMapping("/getMethodLauout")
	public Response<BeMethodLayout> selectById(@RequestParam("methodStepId") String methodStepId,
			@RequestParam("layoutCode") String layoutCode) {
		return Response.ok(beMethodLayoutService.selectById(methodStepId, layoutCode));
	}
}
